function show_user(){
    document.getElementById("user_home").style.display="inline";
    document.getElementById("fruit_transport").style.display="none";
    document.getElementById("fruit_tomorrow").style.display="none";
    document.getElementById("statistics").style.display="none";
    document.getElementById("relation").style.display="none";
    document.getElementById("top_transport").style.height="0px";
    document.getElementById("graph_input").style.display="none";

}
function show_transport(){
    document.getElementById("user_home").style.display="none";
    document.getElementById("fruit_transport").style.display="inline";
    document.getElementById("top_transport").style.height="30px";
    document.getElementById("fruit_tomorrow").style.display="none";
    document.getElementById("statistics").style.display="none";
    document.getElementById("relation").style.display="none";
    document.getElementById("graph_input").style.display="none";
}
function show_tomorrow(){
    document.getElementById("user_home").style.display="none";
    document.getElementById("statistics").style.display="none";
    document.getElementById("relation").style.display="none";
    document.getElementById("fruit_transport").style.display="none";
    document.getElementById("top_transport").style.height="0px";
    document.getElementById("fruit_tomorrow").style.display="inline";
    document.getElementById("graph_input").style.display="none";
}
function show_statistics(){
    document.getElementById("user_home").style.display="none";
    document.getElementById("fruit_transport").style.display="none";
    document.getElementById("top_transport").style.height="0px";
    document.getElementById("fruit_tomorrow").style.display="none";
    document.getElementById("relation").style.display="none";
    document.getElementById("statistics").style.display="inline";
    document.getElementById("graph_input").style.display="none";
}
function show_relation(){
    document.getElementById("user_home").style.display="none";
    document.getElementById("fruit_transport").style.display="none";
    document.getElementById("top_transport").style.height="0px";
    document.getElementById("fruit_tomorrow").style.display="none";
    document.getElementById("relation").style.display="inline";
    document.getElementById("statistics").style.display="none";
    document.getElementById("graph_input").style.display="inline";
}

function add_point(){
//设置新的卡片
   let div = document.createElement("div");
   div.className="point_one";
//   设置横向输入框
   let label_1 = document.createElement('label');
   let input_x = document.createElement('input');
   input_x.className = 'point_one_input';
   input_x.type = 'number';
   input_x.name = 'move_x';
   input_x.value = "0";
   input_x.addEventListener('change', new_point);
   let textnode = document.createTextNode("横向(米)");
   label_1.appendChild(textnode);
   label_1.appendChild(input_x);
   div.appendChild(label_1);
   document.getElementById('point_set').appendChild(div);
// 设置纵向输入框
   let label_2 = document.createElement('label');
   let input_y = document.createElement('input');
   input_y.className = 'point_one_input';
   input_y.type = 'number';
   input_y.name = 'move_y';
   input_y.value = "0";
   input_y.addEventListener('change', new_point);
   let br = document.createElement('br');
   let textnode2 = document.createTextNode("纵向(米)");
   label_2.appendChild(textnode2);
   label_2.appendChild(input_y);
   label_2.appendChild(br);
   div.appendChild(label_2);
//   设置按钮
   let input_add = document.createElement('input');
   input_add.className = 'button';
   input_add.type = 'button';
   input_add.value = '添加';
   input_add.name = 'add_point';
   input_add.addEventListener("click",add_point);

   let input_del = document.createElement('input');
   input_del.className = 'button';
   input_del.type = 'button';
   input_del.value = '删除';
   input_del.name = 'del_point';
   input_del.addEventListener('click', removeElement)

   div.appendChild(input_add);
   div.appendChild(input_del);

   insertAfter(div, window.event.target.parentNode);
}
//删除目标卡片
function removeElement(){
    let _parentElement = window.event.target.parentNode;
    let _grandparentElemnt = _parentElement.parentNode;
    if(_grandparentElemnt){
        _grandparentElemnt.removeChild(_parentElement);
    }
    new_point();
}
//插入新的卡片
function insertAfter(newElement, targetElement){
    let parent = targetElement.parentNode;
    if (parent.lastChild == targetElement) {
        // 如果最后的节点是目标元素，则直接添加。因为默认是最后
        parent.appendChild(newElement);
    }
    else {
        parent.insertBefore(newElement, targetElement.nextSibling);
        //如果不是，则插入在目标元素的下一个兄弟节点 的前面。也就是目标元素的后面
    }
}
// 添加新的点
function new_point(){
    let move_x = document.getElementsByName("move_x");
    let move_y = document.getElementsByName("move_y");
    let textnode = "M";
    for(let i = 0; i<move_x.length; i++){
       if (move_x[i].value != "" && move_y[i].value != "" ){
            textnode = textnode + " l" + move_x[i].value + " " + move_y[i].value;
       }
    }
    document.getElementById("draw_garden").setAttribute('d', textnode.replace("M l", "M")+"Z");
}
// 设置为只读
function user_readonly(){
    document.getElementById('person_name').setAttribute('readonly', "readonly");
    document.getElementById('store_name').setAttribute('readonly', "readonly");
    document.getElementById('gender_m').setAttribute('disabled', "disabled");
    document.getElementById('gender_f').setAttribute('disabled', "disabled");
    document.getElementById('province').setAttribute('disabled', "disabled");
    document.getElementById('city').setAttribute('disabled', "disabled");
    document.getElementById('district').setAttribute('disabled', "disabled");
    document.getElementById('phone_number').setAttribute('readonly', "readonly");
}
//设置为可修改
function user_write(){
    document.getElementById('person_name').removeAttribute('readonly');
    document.getElementById('store_name').removeAttribute('readonly');
    document.getElementById('gender_m').removeAttribute('disabled');
    document.getElementById('gender_f').removeAttribute('disabled');
    document.getElementById('province').removeAttribute('disabled');
    document.getElementById('city').removeAttribute('disabled');
    document.getElementById('district').removeAttribute('disabled');
    document.getElementById('phone_number').removeAttribute('readonly');
}
//显示修改果园形状的div
function show_change_fruit(){
    if (document.getElementById("point_set").style.display == "none"){
        document.getElementById("point_set").style.display = "inline-block";
        document.getElementById('change_garden').value = "关闭";
        document.getElementById('div_change_fruit').style.width = "73%";
    } else{
        document.getElementById("point_set").style.display = "none";
        document.getElementById('change_garden').value = "修改";
        document.getElementById('div_change_fruit').style.width = "100%";
    }
}
//获取文件的名字
function add_file(){
	let file = document.getElementById('into_file');
	let fileName = file.files[0].name;
	document.getElementById('filename').innerHTML = "："+fileName;
}
//显示或隐藏录入窗口
function is_into(){
    if (document.getElementById('into_data').style.display =="none"){
        document.getElementById('into_data').style.display = "inline";
    } else{
        document.getElementById('into_data').style.display = "none";
    }
}
//禁止批量录入
function close_file(){
    document.getElementById('into_file').setAttribute('disabled', "disabled");
    document.getElementById('into_oder_number').removeAttribute('disabled');
    document.getElementById('into_maturity').removeAttribute('disabled');
    document.getElementById('into_type').removeAttribute('disabled');
    document.getElementById('into_origin').removeAttribute('disabled');
    document.getElementById('into_destination').removeAttribute('disabled');
    document.getElementById('into_operator').removeAttribute('disabled');
    document.getElementById('into_transport_number').removeAttribute('disabled');
}
//禁止手动录入
function close_input(){
    document.getElementById('into_file').removeAttribute('disabled');
    document.getElementById('into_oder_number').setAttribute('disabled', "disabled");
    document.getElementById('into_maturity').setAttribute('disabled', "disabled");
    document.getElementById('into_type').setAttribute('disabled', "disabled");
    document.getElementById('into_origin').setAttribute('disabled', "disabled");
    document.getElementById('into_destination').setAttribute('disabled', "disabled");
    document.getElementById('into_operator').setAttribute('disabled', "disabled");
    document.getElementById('into_transport_number').setAttribute('disabled', "disabled");
}
//显示智慧农图
function show_mean(){
    if (document.getElementById('statistics').style.display == "inline"){
        document.getElementById("inform").style.display="block";
    }
}
function hidden_mean(){
   if (document.getElementById('statistics').style.display == "inline"){
         document.getElementById("inform").style.display="none";
   }
}
function change(){
  var name =  "statistics\\" +window.event.srcElement.innerHTML+"产量-2001-2020.html";
  document.getElementById('page1').src = name;
 }

window.onload = function(){ show_transport(); user_readonly(); document.getElementById("point_set").style.display = "none";
document.getElementById("into_data").style.display = "none";document.getElementById('one_do').click();
};